package org.jsping.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.jsping.dao.IHailFellowDao;
import org.jsping.entity.User;

public class HailFellowDaoImpl extends BaseDao implements IHailFellowDao {

	/**
	 * 根据用户id来获取好友列表
	 */
	@Override
	public List<User> getHailFellowList(int id) {
		
		List<User> list = new ArrayList<User>();
		
		String sql = "select Fid,Uname,Sex,Image from HailFellow as h,`User` as u where h.Fid = u.Uid and h.uid = ?";
		
		try {
			ResultSet rs = this.executeQuery(sql, id);
			while(rs.next()) {
				User u = new User();
				u.setUid(rs.getInt("Fid"));
				u.setUname(rs.getString("Uname"));
				u.setSex(rs.getInt("Sex"));
				u.setImage(rs.getString("Image"));
				list.add(u);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.releaseAll();
		}
		return list;
	}

}
